import AlgUtil from "../../../libs/utils/AlgUtil";
import { BaseFightLogic } from "../BaseFightLogic";
import IFightFilter from "../strategy/IFightFilter";
import PermitFilter from "./PermitFilter";

/*****************************
 *@file: RandomFind
 *@author: 陈吕唐
 *@desc: 随机选择指定数量战斗单位策略(从可选单位中随机选择)
 *@date: 2024-02-29	09:42
 *****************************/
export default class RandomFilter implements IFightFilter {

    /**
     * 选择数量
     */
    private _number: number = 1;

    protected permitFind: IFightFilter = new PermitFilter();


    public filter(array: readonly BaseFightLogic[]): BaseFightLogic[] {
        if (array.length <= this.number) {
            return [...array];
        }

        let result = AlgUtil.pickRandomUniqueItems(array, this.number);
        return result;
    }

    public get number(): number {
        return this._number;
    }

    public set number(value: number) {
        this._number = value;
    }
}